import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

// Vant声明和按需引入
import Components from 'unplugin-vue-components/vite'
import { VantResolver } from 'unplugin-vue-components/resolvers'
import postCssPxToRem from 'postcss-pxtorem'

// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) => {
  console.log('---------------------')
  console.log(command, mode)
  console.log('---------------------')

  const base = {
    server: {
      port: 5187,
      open: true,
    },
    plugins: [
      vue(),
      Components({
        resolvers: [VantResolver()],
      }),
    ],
    resolve: {
      alias: {
        '@': fileURLToPath(new URL('./src', import.meta.url)),
      },
    },
    css: {
      postcss: {
        plugins: [
          postCssPxToRem({
            rootValue: 37.5,
            propList: ['*'], // 需要转换的css属性，默认*全部
            selectorBlackList: ['appview'],
          }),
        ],
      },
    },
  }
  return base
})
